import {
  CHANGE_SONGS_OF_ARTIST,
  CHANGE_ENTER_LOADING,
  CHANGE_ARTIST
} from './constant'
import { fromJS } from 'immutable'
import { getSingerRequest } from '../../../api/request'

const changeArtist = data => ({
  type: CHANGE_ARTIST,
  data: fromJS(data)
})

const changeSongsOfArtist = data => ({
  type: CHANGE_SONGS_OF_ARTIST,
  data: fromJS(data)
})

export const changeEnterLoading = data => ({
  type: CHANGE_ENTER_LOADING,
  data
})

export const getSinger = id => {
  return dispatch => {
    getSingerRequest(id).then(res => {
      if (res) {
        dispatch(changeArtist(res.artist))
        dispatch(changeSongsOfArtist(res.hotSongs))
        dispatch(changeEnterLoading(res.false))
      }
    })
  }
}
